package com.mt.mtyx.common.utils.generate.generate.config;


import com.mt.mtyx.common.utils.generate.generate.code.GenerateMethod;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

/**
 * @author WMT
 * @Date 2023/5/26 17:27
 */
public class ControllerCodeConfig {

    private String controllerName;

    private String controllerFormat = "%sController";

    private String supperClass;

    private boolean enableRestController;

    private String controller = "org.springframework.stereotype.Controller";

    private String restController = "org.springframework.web.bind.annotation.RestController";

    private String requestMapping = "org.springframework.web.bind.annotation.RequestMapping";

    private String postMapping = "org.springframework.web.bind.annotation.PostMapping";

    private Set<String> importPackage;

    /**
     * 生成的方法隐射 如果要忽略某个方法 则将他的value值设置为null即可
     */
    private final Map<String, GenerateMethod> method;

    {
        method = new LinkedHashMap<>();
        method.put("INSERT", new GenerateMethod("INSERT", null, "save%s", null, null, null, null, null));
        method.put("DELETE", new GenerateMethod("DELETE", null, "remove%s", null, null, null, null, null));
        method.put("UPDATE", new GenerateMethod("UPDATE", null, "update%s", null, null, null, null, null));
        method.put("LIST", new GenerateMethod("LIST", null, "select%sList", null, null, null, null, null));
        method.put("ONE", new GenerateMethod("ONE", null, "selectOne%s", null, null, null, null, null));
    }

    public String getControllerName() {
        return controllerName;
    }

    public ControllerCodeConfig controllerName(String controllerName) {
        this.controllerName = controllerName;
        return this;
    }

    public String getControllerFormat() {
        return controllerFormat;
    }

    public ControllerCodeConfig controllerFormat(String controllerFormat) {
        this.controllerFormat = controllerFormat;
        return this;
    }

    public String getSupperClass() {
        return supperClass;
    }

    public ControllerCodeConfig supperClass(String supperClass) {
        this.supperClass = supperClass;
        return this;
    }

    public boolean isEnableRestController() {
        return enableRestController;
    }

    public ControllerCodeConfig enableRestController(boolean enableRestController) {
        this.enableRestController = enableRestController;
        return this;
    }

    public String getController() {
        return controller;
    }

    public ControllerCodeConfig controller(String controller) {
        this.controller = controller;
        return this;
    }

    public String getRestController() {
        return restController;
    }

    public ControllerCodeConfig restController(String restController) {
        this.restController = restController;
        return this;
    }

    public String getRequestMapping() {
        return requestMapping;
    }

    public ControllerCodeConfig requestMapping(String requestMapping) {
        this.requestMapping = requestMapping;
        return this;
    }

    public String getPostMapping() {
        return postMapping;
    }

    public ControllerCodeConfig postMapping(String postMapping) {
        this.postMapping = postMapping;
        return this;
    }

    public Set<String> getImportPackage() {
        return importPackage;
    }

    public ControllerCodeConfig importPackage(Set<String> importPackage) {
        this.importPackage = importPackage;
        return this;
    }

    public Map<String, GenerateMethod> getMethod() {
        return method;
    }

    public ControllerCodeConfig methodMap(Consumer<Map<String, GenerateMethod>> methodMap) {
        methodMap.accept(method);
        return this;
    }

}
